//
// Created by richard on 2019/11/18.
//

#include "SimQButton.h"
#include <iostream>

SimQButton::SimQButton(const QString &text, QWidget *parent, uint8_t *outputAddr)
: QPushButton(text, parent),outputAddr(outputAddr) {
    connect(this, &QPushButton::pressed, this, &SimQButton::handlePress);
    connect(this, &QPushButton::released, this, &SimQButton::handleRelease);
}

void SimQButton::revertPush(bool flag) {
    this->revertFlag = flag;
}

void SimQButton::handlePress() {
    bool value = !this->revertFlag;
    if(this->outputAddr != nullptr){
        *this->outputAddr = value;
    }
    std::cout<<"handle press"<< std::endl;
}

void SimQButton::handleRelease() {
    bool value = this->revertFlag;
    if(this->outputAddr != nullptr){
        *this->outputAddr = value;
    }
    std::cout<<"handle release"<< std::endl;
}

SimQButton::~SimQButton() = default;
